package com.moyun;

import com.moyun.websocket.util.ErrorUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动通用主程序
 *
 * @author Zhao Jiruan
 * @EnableCaching开启缓存
 */
@SpringBootApplication
@Slf4j
@MapperScan("com.moyun.**.mapper")
@EnableAsync
@EnableCaching
@EnableTransactionManagement
public class MoYunBaseApplication {

    public static void main(String[] args) {
        SpringApplication.run(MoYunBaseApplication.class, args);
    }

    /**
     * 端口
     */
    @Value("${server.port}")
    private String port;

    /**
     * 启动成功
     */
    @Bean
    public ApplicationRunner applicationRunner() {
        return applicationArguments -> {
            try {
                //获取本机内网IP
                log.info("启动成功：" + "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + port);
                log.info("管理员账号：{},密码：{}", "admin", "123456");
            } catch (UnknownHostException e) {
                //输出到日志文件中
                log.error(ErrorUtil.errorInfoToString(e));
            }
        };
    }

}
